<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\TaskRepository")
 */
class Task
{
    /**
     * @Groups({"task"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Groups({"task"})
     * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="tasks")
     * @ORM\JoinColumn(nullable=false)
     */
    private $user;

    /**
     * @Groups({"task"})
     * @ORM\ManyToOne(targetEntity="App\Entity\Category")
     */
    private $cat1;

    /**
     * @Groups({"task"})
     * @ORM\ManyToOne(targetEntity="App\Entity\Category")
     */
    private $cat2;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="json", nullable=true)
     */
    private $favor = [];

    /**
     * @Groups({"task"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $favorProvince;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $favorCity;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $favorArea;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $title;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="text", nullable=true)
     */
    private $tips;

    /**
     * @Groups({"task"})
     * @ORM\ManyToOne(targetEntity="App\Entity\UserAddress")
     * @ORM\JoinColumn(nullable=false)
     */
    private $address;

    /**
     * @Groups({"task"})
     * @ORM\ManyToOne(targetEntity="App\Entity\UserContact")
     * @ORM\JoinColumn(nullable=false)
     */
    private $contact;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="string", length=255)
     */
    private $sn;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $bookAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $expireAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $hireAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $confirmAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $finishAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="datetime")
     */
    private $createAt;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="smallint")
     */
    private $status;

    /**
     * @Groups({"task"})
     * @ORM\Column(type="array", nullable=true)
     */
    private $pics = [];

    /**
     * @Groups({"task"})
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $type;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $callBefore;

    /**
     * @Groups({"task"})
     * @ORM\OneToMany(targetEntity="App\Entity\TaskVote", mappedBy="task")
     */
    private $vote;

    /**
     * @ORM\OneToOne(targetEntity="App\Entity\Orders", cascade={"persist", "remove"})
     */
    private $orders;

    public function __construct()
    {
        $this->vote = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getCat1(): ?Category
    {
        return $this->cat1;
    }

    public function setCat1(?Category $cat1): self
    {
        $this->cat1 = $cat1;

        return $this;
    }

    public function getCat2(): ?Category
    {
        return $this->cat2;
    }

    public function setCat2(?Category $cat2): self
    {
        $this->cat2 = $cat2;

        return $this;
    }

    public function getFavor(): ?array
    {
        return $this->favor;
    }

    public function setFavor(?array $favor): self
    {
        $this->favor = $favor;

        return $this;
    }

    public function getFavorProvince(): ?string
    {
        return $this->favorProvince;
    }

    public function setFavorProvince(?string $favorProvince): self
    {
        $this->favorProvince = $favorProvince;

        return $this;
    }

    public function getFavorCity(): ?string
    {
        return $this->favorCity;
    }

    public function setFavorCity(?string $favorCity): self
    {
        $this->favorCity = $favorCity;

        return $this;
    }

    public function getFavorArea(): ?string
    {
        return $this->favorArea;
    }

    public function setFavorArea(?string $favorArea): self
    {
        $this->favorArea = $favorArea;

        return $this;
    }

    public function getTips(): ?string
    {
        return $this->tips;
    }

    public function setTips(?string $tips): self
    {
        $this->tips = $tips;

        return $this;
    }

    public function getAddress(): ?UserAddress
    {
        return $this->address;
    }

    public function setAddress(?UserAddress $address): self
    {
        $this->address = $address;

        return $this;
    }

    public function getContact(): ?UserContact
    {
        return $this->contact;
    }

    public function setContact(?UserContact $contact): self
    {
        $this->contact = $contact;

        return $this;
    }

    public function getSn(): ?string
    {
        return $this->sn;
    }

    public function setSn(string $sn): self
    {
        $this->sn = $sn;

        return $this;
    }

    public function getBookAt(): ?\DateTimeInterface
    {
        return $this->bookAt;
    }

    public function setBookAt(?\DateTimeInterface $bookAt): self
    {
        $this->bookAt = $bookAt;

        return $this;
    }

    public function getExpireAt(): ?\DateTimeInterface
    {
        return $this->expireAt;
    }

    public function setExpireAt(?\DateTimeInterface $expireAt): self
    {
        $this->expireAt = $expireAt;

        return $this;
    }

    public function getHireAt(): ?\DateTimeInterface
    {
        return $this->hireAt;
    }

    public function setHireAt(?\DateTimeInterface $hireAt): self
    {
        $this->hireAt = $hireAt;

        return $this;
    }

    public function getConfirmAt(): ?\DateTimeInterface
    {
        return $this->confirmAt;
    }

    public function setConfirmAt(?\DateTimeInterface $confirmAt): self
    {
        $this->confirmAt = $confirmAt;

        return $this;
    }

    public function getFinishAt(): ?\DateTimeInterface
    {
        return $this->finishAt;
    }

    public function setFinishAt(?\DateTimeInterface $finishAt): self
    {
        $this->finishAt = $finishAt;

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getStatus(): ?int
    {
        return $this->status;
    }

    public function setStatus(int $status): self
    {
        $this->status = $status;

        return $this;
    }

    public function getPics(): ?array
    {
        return $this->pics;
    }

    public function setPics(?array $pics): self
    {
        $this->pics = $pics;

        return $this;
    }

    public function getType(): ?int
    {
        return $this->type;
    }

    public function setType(?int $type): self
    {
        $this->type = $type;

        return $this;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(?string $title): self
    {
        $this->title = $title;

        return $this;
    }

    public function getCallBefore(): ?string
    {
        return $this->callBefore;
    }

    public function setCallBefore(?string $callBefore): self
    {
        $this->callBefore = $callBefore;

        return $this;
    }

    /**
     * @return Collection|TaskVote[]
     */
    public function getVote(): Collection
    {
        return $this->vote;
    }

    public function addVote(TaskVote $vote): self
    {
        if (!$this->vote->contains($vote)) {
            $this->vote[] = $vote;
            $vote->setTest($this);
        }

        return $this;
    }

    public function removeVote(TaskVote $vote): self
    {
        if ($this->vote->contains($vote)) {
            $this->vote->removeElement($vote);
            // set the owning side to null (unless already changed)
            if ($vote->getTest() === $this) {
                $vote->setTest(null);
            }
        }

        return $this;
    }

    public function getOrders(): ?Orders
    {
        return $this->orders;
    }

    public function setOrders(?Orders $orders): self
    {
        $this->orders = $orders;

        return $this;
    }
}
